<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<link type="text/css" rel="stylesheet" href="../zxy/css/common/edit_win.css"/>
	<table id="zxy_eh_dg"></table>
	
	<div id="zxy_eh_tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="zxy_eh_append()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="zxy_eh_remove()">删除</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="zxy_eh_edit()">编辑</a>
	</div>
	<!-- 编辑或添加的窗口 -->
	<div id="zxy_eh_win" class="easyui-window">
		<form id="zxy_eh_win_form" class="easyui-form" method="post">
			<input type="hidden" id="zxy_eh_id" name="id"/>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">学校名称</span>
				<input name="schoolName" class="easyui-textbox zxy_edit_win_text_content" data-options="required:true"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">学历</span>
				<input name="education" class="easyui-textbox zxy_edit_win_text_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">专业</span>
				<input name="major" class="easyui-textbox zxy_edit_win_text_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">联系人</span>
				<input name="contactPerson" class="easyui-textbox zxy_edit_win_text_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">联系电话</span>
				<input name="contactTel" class="easyui-textbox zxy_edit_win_text_content" data-options="validType:'mobile'"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">地址</span>
				<input name="address" class="easyui-validatebox zxy_edit_win_text_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">开始日期</span>
				<input name="beginDate" class="easyui-datebox zxy_edit_win_date_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">结束日期</span>
				<input name="endDate" class="easyui-datebox zxy_edit_win_date_content"/>
			</div>
			<div class="zxy_edit_win">
				<span class="zxy_edit_win_title">备注</span>
				<input name="remark" class="easyui-textbox zxy_edit_win_text_content"/>
			</div>
		</form>
	</div>
	
	<script type="text/javascript">
		$("#zxy_eh_win").window({
			width:600,
		    height:400,
		    modal:true,
		    title:'编辑',
		    minimizable:false,
		    maximizable:false,
		    collapsible:false,
		    closed:true,
		    resizable:false,
		    tools:[{
				iconCls:'icon-save',
				handler:function(){
					if(!$("#zxy_eh_win_form").form("validate")){
						$.messager.alert("Warning","输入值无效");
						return;
					}
					$("#zxy_eh_win_form").form('submit',{
						onSubmit: function(param){
							param.empId=zxy_eh_empId;
							console.log(param);
					    },
					    success:function(data){
					    	data=$.parseJSON(data);
					    	console.log(data);
					    	$.messager.alert("",data.msg);
					    	$("#zxy_eh_win").window('close');
					    	$("#zxy_ei_emp_education_history").panel('refresh','../emp/empEducationHistory?empId='+zxy_eh_empId);
					    },
					    error:function(){
					    	$.messager.alert("操作失败");
					    }
					});
				}
			},{
				iconCls:'icon-clear',
				handler:function(){
					$("#zxy_eh_win_form").form('reset');
				}
			}]
		    
		});
		
		$(".zxy_edit_win_date_content").datebox({
			width:'150',
			height:'30',
		});
		$(".zxy_edit_win_text_content").textbox({
			width:'150',
			height:'30',
		});
		
		//验证规则
		$.extend($.fn.validatebox.defaults.rules, {
			//移动手机号码验证
			mobile: {//value值为文本框中的值
		        validator: function (value) {
		            var reg = /^1[3|4|5|8|9]\d{9}$/;
		            return reg.test(value);
		        },
		        message: '输入手机号码格式不准确.'
		    },
		});
		
		
		var empEducationHistories='${empEducationHistories}';
		var zxy_eh_empId='${empId}';
		empEducationHistories=$.parseJSON(empEducationHistories);
		for(var i=0;i<empEducationHistories.length;i++){
			if(empEducationHistories[i].beginDate != undefined){
				var bd=new Date(empEducationHistories[i].beginDate);
				empEducationHistories[i].beginDate=bd.getFullYear()+"-"+(bd.getMonth()+1)+"-"+bd.getDate();
			}
			if(empEducationHistories[i].endDate != undefined){
				var ed=new Date(empEducationHistories[i].endDate);
				empEducationHistories[i].endDate=ed.getFullYear()+"-"+(ed.getMonth()+1)+"-"+ed.getDate();
			}
		}
		console.log(empEducationHistories);
		$(function() {
			$('#zxy_eh_dg').datagrid({
				//请求地址
			    data:empEducationHistories,
			    columns:[[
			    	{field:'',title:'',checkbox:true},
					{field:'schoolName',title:'学校名称',width:'10%'},
					{field:'education',title:'学历',width:'10%'},
					{field:'major',title:'专业',width:'10%',align:'center'},
					{field:'contactPerson',title:'联系人',width:'10%',align:'center'},
					{field:'contactTel',title:'联系电话',width:'10%',align:'center'},
					{field:'address',title:'地址',width:'20%',align:'center'},
					{field:'beginDate',title:'开始日期',width:'10%',align:'center'},
					{field:'endDate',title:'结束日期',width:'10%',align:'center'},
					{field:'remark',title:'备注',width:'10%',align:'center'},
			    ]],
			    fitColumns:true,
			    //隔行变色
			    striped:true,
			    nowrap:true,
			    //显示行号
			    rownumbers:true,
				toolbar:'#zxy_eh_tb',
				//只有当用户点击了复选框时，才会选中/取消选中复选框。
				checkOnSelect:true,
			});
		});
	
		function zxy_eh_append(){
			$("#zxy_eh_win_form").form('clear');
			$("#zxy_eh_win_form").form({url:'../empEducationHistory/addEmpEducationHistory'});
			$("#zxy_eh_win").window({'title':'新增'});
			$("#zxy_eh_win").window('open');
		}
		function zxy_eh_remove(){
			$.messager.confirm("操作提示", "您确定要删除吗？", function (data) {
				if(data) {
					var rows=$("#zxy_eh_dg").datagrid("getChecked");
					var id_arr=[];
					for(var i=0;i<rows.length;i++){
						id_arr.push(rows[i].id);
					}
					id_arr=JSON.stringify(id_arr);
					$.ajax({
						url:'../empEducationHistory/deleteEmpEducationHistoryById',
						data:{
							"id_arr":id_arr,
						},
						success:function(data){
					    	console.log(data);
							data=$.parseJSON(data);
					    	console.log(data);
					    	$.messager.alert("",data.msg);
					    	$("#zxy_eh_win").window('close');
					    	$("#zxy_ei_emp_education_history").panel('refresh','../emp/empEducationHistory?empId='+zxy_eh_empId);
						}
					});
				}
			});
		}
		
		//编辑一行，将该行的数据填充进表单
		function zxy_eh_edit(){
			if($("#zxy_eh_dg").datagrid("getChecked").length!=1){
				$.messager.alert('操作提示','请选择一行进行编辑!');
				return;
			}
			$("#zxy_eh_win_form").form('clear');
			var row=$("#zxy_eh_dg").datagrid("getChecked")[0];
			console.log(row);
			$("#zxy_eh_win_form").form('load',row);
			$("#zxy_eh_win_form").form({url:'../empEducationHistory/updateEmpEducationHistoryById'});
			$("#zxy_eh_win").window({'title':'编辑'});
			$("#zxy_eh_win").window('open');
		}

	</script>
</body>
</html>